<template>
  <el-dialog
    title="设置喷灌机参数"
    :visible.sync="dialogVisible"
    width="800px"
  >
    <el-form ref="setForm" size="medium" :model="formData" label-width="80px">
      <el-divider content-position="left"><b>喷灌机基础信息设置</b></el-divider>
      <el-row>
        <el-col :span="12">
          <el-form-item label="半径" prop="radius">
            <el-input v-model.number="formData.radius" type="number" placeholder="半径" clearable>
              <template slot="append">m</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="有效半径" prop="radius_valid">
            <el-input v-model.number="formData.radius_valid" type="number" placeholder="半径" clearable>
              <template slot="append">m</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="水泵流量" prop="flow">
            <el-input v-model.number="formData.flow" type="number" placeholder="水泵流量" clearable>
              <template slot="append">m³/h</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="行走速度" prop="speed">
            <el-input v-model.number="formData.speed" type="number" placeholder="行走速度" clearable>
              <template slot="append">m/min</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="left"><b>喷灌机自动执行计划参数设置</b></el-divider>
      <el-row>
        <el-col :span="12">
          <el-form-item label="运行方向" prop="autoDirection">
            <el-radio-group v-model.number="formData.autoDirection">
              <el-radio-button :label="1">正向</el-radio-button>
              <el-radio-button :label="0">反向</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="延时启动" prop="autoDelay">
            <el-input v-model.number="formData.autoDelay" type="number" placeholder="延时启动" clearable>
              <template slot="append">min</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="尾枪设置" prop="endGun">
            <el-radio-group v-model.number="formData.endGun">
              <el-radio-button :label="1">打开</el-radio-button>
              <el-radio-button :label="0">关闭</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="停止方位" prop="autoStopTo">
            <el-input v-model.number="formData.autoStopTo" type="number" placeholder="停止方位" clearable>
              <template slot="append">°</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="left"><b>到达灌水下限后自动生成采集数据计划时间设置</b></el-divider>
      <el-form-item label="时间设定" prop="autoStopTo">
            <el-input v-model.number="formData.autoPlanTime" type="number" placeholder="时间设定" clearable>
              <template slot="prepend">达到灌水下限发送消息后</template>
              <template slot="append">小时 后自动执行走喷灌机采集数据计划</template>
            </el-input>
          </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { setOne, readOne } from '@/api/device'
export default {
  data() {
    return {
      dialogVisible: false,
      serialno: '',
      formData: {
        radius: '',
        radius_valid: '',
        flow: '',
        speed: '',
        autoDirection: '',
        autoDelay: '',
        autoStopTo: '',
        endGun: ''
      }
    }
  },
  methods: {
    async show(row) {
      const { data } = await readOne(row.serialno)
      this.formData = data.extention
      this.serialno = row.serialno
      this.dialogVisible = true
    },
    hide() {
      this.dialogVisible = false
    },
    async submit() {
      const { msg } = await setOne(this.serialno, this.formData)
      this.$message.success(msg)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
